<?php

/**
 * Goods_color_model short summary.
 *
 * Goods_color_model description.
 *
 * @version 1.0
 * @author GALAXY
 */
class Goods_color_model extends CI_Model
{
    public $goods_color_id;
    public $goods_id;
    public $color_id;
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function get_all_color_by_goods_color($goodsid)
    {
        $sql="SELECT g.color_id,g.goods_color_id,g.goods_id,c.title,c.colorkey FROM goods_color g LEFT JOIN color c on c.color_id=g.color_id WHERE g.goods_id=$goodsid";
        return $this->db->query($sql)->result_array();
    }

    public function get_all_goods_color_by_goods_id($goods_id)
    {
        $sql="SELECT goods_color.*,color.title,color.colorkey FROM goods_color INNER JOIN color on color.color_id=goods_color.color_id where goods_id=$goods_id";
        return $this->db->query($sql)->result();
    }

    public function insert_goods_color($goodscolorModel)
    {
        return $this->db->insert('goods_color',$goodscolorModel);
    }

    public function del_goods_color($goodscolorModel)
    {
        $this->db->trans_begin();
        $this->db->delete('goods_color',array('goods_id'=>$goodscolorModel->goods_id,'color_id'=>$goodscolorModel->color_id));
        $this->db->delete('goods_inventory',array('goods_id'=>$goodscolorModel->goods_id,'goods_color_id'=>$goodscolorModel->color_id));
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            return 0;
        }
        else
        {
            $this->db->trans_commit();
            return 1;
        }
    }
}